package com.moyou.weichat.listener;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;

import com.moyou.weichat.R;
import com.moyou.weichat.WeiChatApplication;
import com.moyou.weichat.utils.ConstantUtils;

/**
 * sj ：2017年10月16日11:03:11
 * name: ts
 * 用途:注册的输入监听
 */

public class RegisterTextWatcherListener implements TextWatcher {
    private EditText loginUserPass;
    private Button meloginBuLogin;
    private int type;
    private Context context;

    public RegisterTextWatcherListener(EditText loginUserPass, Button meloginBuLogin, int type, Context context) {
        this.loginUserPass = loginUserPass;
        this.meloginBuLogin = meloginBuLogin;
        this.type = type;
        this.context = context;
    }


    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void afterTextChanged(Editable editable) {
        //判断手机号码的位数
        String content = editable.toString();
        if (type == ConstantUtils.LOGIN_TYPE_NAME){
            if (content.length() >= ConstantUtils.PHONE_LENGTH && loginUserPass.getText().length() >= ConstantUtils.PHONE_LENGTH_PASS) {
                meloginBuLogin.setEnabled(true);
            } else {
                meloginBuLogin.setEnabled(false);
            }
        }else{
            if (content.length() >= ConstantUtils.PHONE_LENGTH_PASS && loginUserPass.getText().length() >= ConstantUtils.PHONE_LENGTH) {
                meloginBuLogin.setEnabled(true);
            } else {
                meloginBuLogin.setEnabled(false);
            }
        }
    }
}
